/*
 * @FileName: [DictionaryTypeServiceImpl.java]
 * 
 * @Package com.bci.pwtz.service.impl
 * 
 * 
 * Copyright (c) 2011-2015 BCINFO Technology Limited Com.
 * All rights reserved.
 * 
 * This software is the confidential and proprietary
 * information of BCINFO Technology Limited Company
 * ("Confidential Information"). You shall not disclose
 * such Confidential Information and shall use it only
 * in accordance with the terms of the contract agreement
 * you entered into with RKY.
 * 
 * $Rev$
 * $LastChangedDate$
 * $LastChangedBy$
 * 
 * @category ALUMNI
 * 
 * @version 1.1
 * 
 * @author $Author$
 * 
 * Change History:[Formatter: author date description] <br/>
 * 1
 * 2
 * 3
 */

package com.bci.pwtz.service.impl;

import java.util.List;

import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.bci.pwtz.exception.CanNotDeleteException;
import com.bci.pwtz.exception.PwtzDatabaseException;
import com.bci.pwtz.mysql.dao.DictionaryTypeMapper;
import com.bci.pwtz.mysql.model.DictionaryType;
import com.bci.pwtz.service.BusinessRefService;
import com.bci.pwtz.service.CompanyService;
import com.bci.pwtz.service.DictionaryTypeService;

/**
 * 一句话描述 <br/>
 * <p>
 * Description:<br/>
 * <p>
 * TODO 详细描述
 * 
 * <p>
 * For Examples <br/>
 * 
 * <PRE>
 *      TODO 代码使用示例
 * </PRE>
 * <p>
 */
@Service
public class DictionaryTypeServiceImpl implements DictionaryTypeService
{
    private DictionaryTypeMapper    dictionaryTypeMapper;

    private CompanyService          companyService;

    private BusinessRefService businessRefService;

    private static final Logger     _logger = Logger.getLogger(PdbyqServiceImpl.class);

    public DictionaryTypeMapper getDictionaryTypeMapper()
    {
        return dictionaryTypeMapper;
    }

    public void setDictionaryTypeMapper(DictionaryTypeMapper dictionaryTypeMapper)
    {
        this.dictionaryTypeMapper = dictionaryTypeMapper;
    }

    public CompanyService getCompanyService()
    {
        return companyService;
    }

    public void setCompanyService(CompanyService companyService)
    {
        this.companyService = companyService;
    }

   

    public BusinessRefService getBusinessRefService()
    {
        return businessRefService;
    }

    public void setBusinessRefService(BusinessRefService businessRefService)
    {
        this.businessRefService = businessRefService;
    }

    @Override
    public DictionaryType add(DictionaryType dictionaryType) throws PwtzDatabaseException
    {
        if (_logger.isDebugEnabled())
        {
            _logger.debug("add:dictionaryType=" + dictionaryType.toString());
        }
        if (dictionaryType == null)
        {
            if (_logger.isDebugEnabled())
            {
                _logger.debug("add, dictionaryType is null");
            }
            return null;
        }
        try
        {
            dictionaryTypeMapper.insertSelective(dictionaryType);
        }
        catch (DataAccessException _e)
        {
            _logger.error(ExceptionUtils.getStackTrace(_e));
            throw new PwtzDatabaseException();
        }
        return dictionaryType;
    }

    @Override
    public int delete(Long dictionaryTypeId) throws PwtzDatabaseException, CanNotDeleteException
    {
        int result = 0;
        if (_logger.isDebugEnabled())
        {
            _logger.debug("delete:dictionaryTypeId=" + dictionaryTypeId);
        }
        try
        {
            boolean bl = businessRefService.canDelete("T_DICTIONARYTYPE", dictionaryTypeId.toString());
            if (!bl)
            {
                throw new CanNotDeleteException();
            }
            result = dictionaryTypeMapper.deleteByPrimaryKey(dictionaryTypeId);
        }
        catch (DataAccessException _e)
        {
            _logger.error(ExceptionUtils.getStackTrace(_e));
            throw new PwtzDatabaseException();
        }
        return result;
    }

    @Override
    public int update(DictionaryType dictionaryType) throws PwtzDatabaseException
    {
        int result = 0;
        if (_logger.isDebugEnabled())
        {
            _logger.debug("update:dictionaryType=" + dictionaryType.toString());
        }
        if (dictionaryType == null)
        {
            if (_logger.isDebugEnabled())
            {
                _logger.debug("update,dictionaryType is null");
            }
            return 0;
        }
        try
        {
            result = dictionaryTypeMapper.updateByPrimaryKeySelective(dictionaryType);
        }
        catch (DataAccessException _e)
        {
            _logger.error(ExceptionUtils.getStackTrace(_e));
            throw new PwtzDatabaseException();
        }
        return result;
    }

    @Override
    public List<DictionaryType> findDictionaryType() throws PwtzDatabaseException
    {
        List<DictionaryType> list = null;
        try
        {
            list = dictionaryTypeMapper.selectDictionaryType();
        }
        catch (DataAccessException e)
        {
            _logger.error(ExceptionUtils.getStackTrace(e));
            throw new PwtzDatabaseException();
        }
        if (list != null)
        {
            _logger.debug("findDictionaryType:result menu=" + list.toString());
        }
        return list;
    }
}
